<%@ page import="java.io.File" %>
<%@ page import="javax.imageio.ImageIO" %>
<%@ page import="java.awt.*" %>
<%@ page import="java.awt.image.BufferedImage" %>
<%@ page import="com.touzi.utils.QRCodeUtils" %>
<%@ page import="com.touzi.proconfig.ProjectConfig" %>
<%@ page import="com.touzi.mapper.SysconfigMapper" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.touzi.constants.DbCons" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %><%--
  Created by IntelliJ IDEA.
  User: w7851
  Date: 2018/5/31
  Time: 13:20
  To change this template use File | Settings | File Templates.
  邀请图片生成的页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    response.setContentType("image/jpeg");
    out.clear();
    SqlSession sqlSession = ((SqlSessionFactory) application.getAttribute(DbCons.DB_FACTORY)).openSession();
    SysconfigMapper sysconfigMapper=sqlSession.getMapper(SysconfigMapper.class);
    String BASE_URL=sysconfigMapper.getBaseURL();
    sqlSession.close();
    //邀请人的ID
    String inviteID=request.getParameter("inviteid");
    if (inviteID==null){
        inviteID="0";
    }
    String content=BASE_URL+"/mobile/regnew.jsp?recoid="+inviteID;

    Image src= ImageIO.read(new File(application.getRealPath(ProjectConfig.INVITE_PIC)));
    BufferedImage bufferedImage=new BufferedImage(src.getWidth(null), src.getHeight(null),BufferedImage.TYPE_INT_RGB);

    Graphics2D g=bufferedImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    g.drawImage(src.getScaledInstance(src.getWidth(null), src.getHeight(null), Image.SCALE_SMOOTH), 0, 0,null);
    //生成二维码，内容 宽 高
    BufferedImage icon= QRCodeUtils.enCode(content,300,300);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1));

    // 6、水印图片的位置
    g.drawImage(icon, 50, 50, null);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
    // 7、释放资源
    g.dispose();

    ImageIO.write(bufferedImage,"JPG",response.getOutputStream());
%>